package com.qf.agro.service.sys.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.agro.mapper.sys.CompanyMapper;
import com.qf.agro.pojo.sys.Company;
import com.qf.agro.service.sys.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: 六六六
 * @create: 2023-06-29 16:29
 **/
@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    private CompanyMapper companyMapper;


    @Override
    public Page<Company> findPage(Integer pageNum, Integer pageSize, String name) {
        //1. 创建查询条件对象
        LambdaQueryWrapper<Company> wrapper = new LambdaQueryWrapper<>();
        //2.设置查询条件
        wrapper.like(name!=null, Company::getName, name);//where name like %#{name}%
        wrapper.eq(Company::getState,1);
        wrapper.orderByDesc(Company::getId);
        //3 设置分页条件
        Page<Company> page = new Page<>(pageNum, pageSize);
        //4 查询
        page = companyMapper.selectPage(page, wrapper);

        //5 返回
        return page;
    }

    @Override
    public void insert(Company company) {
         companyMapper.insert(company);

    }

    @Override
    public void update(Company company) {
        companyMapper.updateById(company);
    }

    @Override
    public void delete(String id) {
        companyMapper.deleteById(id);
    }
}
